#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProgressBar>
#include <QTimeLine>
#include <qDebug>
#include <QPushButton>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QProgressBar *progressBar = ui->progressBar;
    progressBar->setRange(0, 100);

    // 构造帧范围为 0 - 100，持续时间为 1000 毫秒（1 秒）的 timeline
    QTimeLine *timeLine = new QTimeLine(1000, this);
    timeLine->setFrameRange(0, 100);
    connect(timeLine, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int)));

    // 输出当前帧数
    connect(timeLine, &QTimeLine::frameChanged, [=](int value) {
            qDebug() << value;
        });

    // 启动进度条动画
    QPushButton *startButton = ui->pushButton;
    startButton->setText(QString("开始"));
    connect(startButton, SIGNAL(clicked()), timeLine, SLOT(start()));
}

MainWindow::~MainWindow()
{
    delete ui;
}
